//
//  WSCoinRecordsItemController.m
//  BaseProject
//
//  Created by karong on 2023/8/7.
//

#import "WSCoinRecordsItemController.h"
#import "WSCoinRecordsCell.h"
#import "WSCoinRecordsRequest.h"

@interface WSCoinRecordsItemController ()

@property (weak, nonatomic) IBOutlet UICollectionView *listView;

@property (nonatomic, strong) WSCoinRecordsRequest * request;

@end

@implementation WSCoinRecordsItemController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.request = [WSCoinRecordsRequest new];
    self.request.url = (self.type == 1)?API_CHARONTV_USER_CONSUMELOG:API_CHARONTV_USER_RECHARGELOG;
    [self setEmptyStateTitle:(self.type == 1)?APPLocalized(@"本月还没有消费过哦"):APPLocalized(@"本月还没有充值过哦") state:ListViewEmptyStateEmpty];
    NSDate * date = [NSDate new];
    self.request.year = date.year;
    self.request.month = date.month;
    [self addObserver];
}

- (void)addObserver {
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(refreshDataWithNotification:) name:WSRefreshRecordsNotification object:nil];
}

- (void)refreshDataWithNotification:(NSNotification *)notification {
    NSDictionary * infoDic = [notification object];
    if (infoDic) {
        self.request.year = [infoDic[@"year"] integerValue];
        self.request.month = [infoDic[@"month"] integerValue];
        [self benginRefresh];
    }
}

- (BOOL)disableAutoBeginRefresh {
    return YES;
}

#pragma mark UICollectionViewDelegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    WSCoinRecordsCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WSCoinRecordsCell" forIndexPath:indexPath];
    [cell setDataWithObject:self.dataArray[indexPath.row] type:self.type];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size = CGSizeZero;
    size.width = WSScreenWidth;
    size.height = 63 + self.type * 17;
    return size;
}

@end
